🎖️GitЯра🎖️
Commit 24806c664ad04b2c6aee1407c89d5c2da0b0447c
Parents : ff7653a
Author : James Rich <2199651+jamesarich@users.noreply.github.com>
Signature : Signature validation error
Date : 2026-08-16T08:38:11Z
Committer : GitHub <noreply@github.com>
Date : 2026-08-16T08:38:11Z
fix(ai): read the real inference source instead of hardcoding it (#6732)
Changes
1 files changed, 11 insertions(+), 5 deletions(-)
Diff
diff --git a/androidApp/src/google/kotlin/org/meshtastic/app/ai/GeminiNanoDocAssistant.kt b/androidApp/src/google/kotlin/org/meshtastic/app/ai/GeminiNanoDocAssistant.kt
index a9a637daea..d6af5f4798 100644
--- a/androidApp/src/google/kotlin/org/meshtastic/app/ai/GeminiNanoDocAssistant.kt
+++ b/androidApp/src/google/kotlin/org/meshtastic/app/ai/GeminiNanoDocAssistant.kt
@@ -20,6 +20,7 @@ import co.touchlab.kermit.Logger
import com.google.firebase.Firebase
import com.google.firebase.ai.DownloadStatus
import com.google.firebase.ai.InferenceMode
+import com.google.firebase.ai.InferenceSource
import com.google.firebase.ai.OnDeviceConfig
import com.google.firebase.ai.OnDeviceModelOption
import com.google.firebase.ai.OnDeviceModelStatus
@@ -218,7 +219,9 @@ class GeminiNanoDocAssistant(
try {
val accumulatedText = StringBuilder()
var lastEmitTime = 0L
+ var lastInferenceSource: InferenceSource? = null
onDeviceModel.generateContentStream(prompt).collect { chunk ->
+ lastInferenceSource = chunk.inferenceSource
val text = chunk.text
if (!text.isNullOrEmpty()) {
accumulatedText.append(text)
@@ -230,24 +233,27 @@ class GeminiNanoDocAssistant(
AIDocAssistantResult.Partial(
answer = cleanResponse(accumulatedText.toString()),
sourcePages = contextPages,
- usedOnDeviceModel = true,
+ usedOnDeviceModel = chunk.inferenceSource == InferenceSource.ON_DEVICE,
),
)
}
}
- // Log token usage from last chunk
+ // Log token usage and model version from the last chunk
chunk.usageMetadata?.let { meta ->
Logger.d(tag = TAG) {
- "Tokens — prompt: ${meta.promptTokenCount}, response: ${meta.candidatesTokenCount}, total: ${meta.totalTokenCount}"
+ "Tokens — prompt: ${meta.promptTokenCount}, response: ${meta.candidatesTokenCount}, " +
+ "total: ${meta.totalTokenCount}, source: ${chunk.inferenceSource}, " +
+ "model: ${chunk.modelVersion}"
}
}
}
+ val usedOnDeviceModel = lastInferenceSource == InferenceSource.ON_DEVICE
// Emit final partial to ensure UI has the complete text before Success
emit(
AIDocAssistantResult.Partial(
answer = cleanResponse(accumulatedText.toString()),
sourcePages = contextPages,
- usedOnDeviceModel = true,
+ usedOnDeviceModel = usedOnDeviceModel,
),
)
val onDeviceAnswer = cleanResponse(accumulatedText.toString().trimEnd())
@@ -265,7 +271,7 @@ class GeminiNanoDocAssistant(
AIDocAssistantResult.Success(
answer = onDeviceAnswer,
sourcePages = allSourcePages,
- usedOnDeviceModel = true,
+ usedOnDeviceModel = usedOnDeviceModel,
),
)
return@flow // Success — exit retry loop
Served by rngit 1.5.2 - Generated in 0.07s